import { stringify } from 'qs'
import request from '../utils/request'

/**
 * Created by: 耿德洲
 * Created in: 2019/3/19 09:17
 * description: 这是一个通用的series层，作用是让你不用写service层。
 * rules: {
 *    1.你必须保证你所增加的方法是common类型的。
 *    2.你必须保证在已经理解这个类的前提下修改或者增加公共方法。
 *    3.里面的方法你可以搭配 modal/common 使用，也可以单独使用
 *
 * }
 */

export const queryPost = async params => {
  const { url, ...paramsData } = params
  return request.post(url, {
    method: 'POST',
    data: paramsData,
  })
}

export const arrayPost = async params => {
  const { url, ...paramsData } = params
  return request(url, {
    method: 'POST',
    body: paramsData.list,
  })
}

export const pageablePost = async params => {
  const { url, ...paramsData } = params
  return request.post(`${url}?${stringify(paramsData)}`, {
    method: 'POST',
    data: paramsData,
  })
}

export const editOrDeletePost = async params => {
  const { url, sid, id, ...paramsData } = params
  return request(`${url}/${id || sid}?${stringify(paramsData)}`, {
    method: 'POST',
    body: paramsData,
  })
}

export const listPost = async params => {
  const { url, ...paramsData } = params
  return request(url, {
    method: 'POST',
    body: paramsData,
  })
}


export const queryGet = async params => {
  const { url, sid, id, ...paramsData } = params
  return request(`${url}/${id || sid}?${stringify(paramsData)}`, {
    method: 'GET',
  })
}


export const listGet = async params => {
  const { url, ...paramsData } = params
  return request(`${url}?${stringify(paramsData)}`, {
    method: 'GET',
  })
}


export const editPut = async params => {
  const { url, sid, id, ...paramsData } = params
  return request(`${url}/${id || sid}`, {
    method: 'PUT',
    body: paramsData,
  })
}
export const queryPut = async params => {
  const { url, ...paramsData } = params
  return request(url, {
    method: 'PUT',
    body: paramsData,
  })
}

export const removeDelete = async params => {
  const { url, sid, id, ...paramsData } = params
  return request(`${url}/${id || sid}`, {
    method: 'Delete',
    body: paramsData,
  })
}

export const remove = async params => {
  const { url, sid, id, ...paramsData } = params
  return request(`${url}/${id || sid}?${stringify(paramsData)}`, {
    method: 'Delete',
  })
}

export const postRequestParam = async params => {
  const { url, ...paramsData } = params
  return request(`${url}?${stringify(paramsData)}`, {
    method: 'POST',
    body: paramsData,
  })
}

export const postReq = async params => {
  const { url, ...paramsData } = params
  return request(url, {
    method: 'POST',
    body: paramsData,
  })
}




